from django.http import HttpResponse
from django.shortcuts import render

from blog.models import User


# Create your views here.
def login_view(request):
    return render(request, template_name='login.html')


def reg_view(request):
    if request.method == 'GET':
        return render(request, 'register.html')
    elif request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        old_users = User.objects.filter(username=username)
        if old_users:
            return HttpResponse('用户名已注册')
        # 3.插入数据[明文处理密码]
        User.objects.create(username=username, password=password)
        return HttpResponse('注册成功')

